package com.sgb.packers.view.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.packers.BR;
import com.sgb.packers.R;
import com.sgb.packers.databinding.PackersItemAccountBinding;
import com.sgb.packers.databinding.PackersItemWorksBinding;
import com.sgb.packers.entity.WorkTakeEntity;
import com.swgk.core.base.model.entity.SingleItemConstant;
import com.swgk.core.util.NumberUtil;

import java.util.List;

/**
 * @author 王彬臣
 * @date 2021/11/30
 * @Description 记工流水子item Adapter
 */
public class WorkAccountChildAdapter extends BaseMultiItemQuickAdapter<WorkTakeEntity.ListDTO, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public WorkAccountChildAdapter(List<WorkTakeEntity.ListDTO> data) {
        super(data);
        //点工类型
        addItemType(SingleItemConstant.TYPE_ONE, R.layout.packers_item_works);
        //包工类型
        addItemType(SingleItemConstant.TYPE_TWO, R.layout.packers_item_account);
    }

    @Override
    protected void convert(BaseViewHolder helper, WorkTakeEntity.ListDTO item) {
        switch (item.getItemType()) {
            case SingleItemConstant.TYPE_ONE:
                setWork(helper, item);
                break;
            case SingleItemConstant.TYPE_TWO:
                setAccount(helper, item);
                break;
            default:
                break;
        }
    }

    @SuppressLint("SetTextI18n")
    private void setWork(BaseViewHolder helper, WorkTakeEntity.ListDTO item) {
        PackersItemWorksBinding itemWorksBinding = DataBindingUtil.bind(helper.itemView);
        assert itemWorksBinding != null;
        itemWorksBinding.setVariable(BR.viewModel, item);
        //1按一个工,2按输入工天,3:休息,4:按小时
        if (!TextUtils.isEmpty(item.getWorkType())) {
            switch (item.getWorkType()) {
                case "1":
                case "2":
                    itemWorksBinding.tvWorkTime.setText(NumberUtil.trim0(item.getWorkDuration()) + "个工");
                    break;
                case "3":
                    itemWorksBinding.tvWorkTime.setText("休息");
                    break;
                case "4":
                    itemWorksBinding.tvWorkTime.setText(NumberUtil.trim0(item.getWorkDuration()) + "小时");
                    break;
                default:
                    break;
            }
        }

    }

    @SuppressLint("SetTextI18n")
    private void setAccount(BaseViewHolder helper, WorkTakeEntity.ListDTO item) {
        PackersItemAccountBinding itemWorksBinding = DataBindingUtil.bind(helper.itemView);
        assert itemWorksBinding != null;
        itemWorksBinding.setVariable(BR.viewModel, item);
        if (!TextUtils.isEmpty(item.getQuantitiesUnit()) && !TextUtils.isEmpty(item.getQuantities())) {
            switch (item.getQuantitiesUnit()) {
                case "1":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "平方米");
                    break;
                case "2":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "立方米");
                    break;
                case "3":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "吨");
                    break;
                case "4":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "米");
                    break;
                case "5":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "寸");
                    break;
                case "6":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "个");
                    break;
                case "7":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "次");
                    break;
                case "8":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "天");
                    break;
                case "9":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "块");
                    break;
                case "10":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "组");
                    break;
                case "11":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "台");
                    break;
                case "12":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "捆");
                    break;
                case "13":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "宗");
                    break;
                case "14":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "项");
                    break;
                case "15":
                    itemWorksBinding.tvContractorUnit.setText(item.getQuantities() + "珠");
                    break;
                default:
                    break;
            }
        }
    }
}
